<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>限制地图范围</title>
    <script src="https://openlayers.org/en/v4.5.0/build/ol.js" type="text/javascript"></script>
</head>
<body>
<div id="map" style="width: 100%"></div>
<script>
    //限制了地图的范围不代表不能缩放
    new ol.Map({
        layers: [
            new ol.layer.Tile({source: new ol.source.OSM()})
        ],
        view: new ol.View({
            // 设置地图中心范围（extent）
            extent: [102, 29, 104, 31],
            // 设置成都为地图中心
            center: [104.06, 30.67],
            projection: 'EPSG:4326',
            zoom: 10
        }),
        target: 'map'
    });
</script>
</body>
</html>